﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Text.RegularExpressions;
using ContactManager.Models.Entities;

namespace ContactManager.Models.Validation
{
    public class ContactValidator:IValidator<Contact>
    {
        public ValidationState Validate(Contact contactToValidate)
        {

            ValidationErrorCollection _validationErrorCollection = new ValidationErrorCollection();

            switch (contactToValidate.FirstName)
            {
                case null: _validationErrorCollection.Add("FirstName", "First name is required.");
                    break;
                case "":
                    _validationErrorCollection.Add("FirstName", "First name is required.");
                    break;
            }

            ValidationState _validationState = new ValidationState(_validationErrorCollection);

            return _validationState;

            
            //if (contactToValidate.LastName.Trim().Length == 0)
            //    _validationErrorCollection.Add("LastName", "Last name is required.");
            //if (!PhoneValidator.IsValidNumber(contactToValidate.Phone, "NZ"))
            //    _validationErrorCollection.Add("Phone", "Invalid phone number.");
            //if (contactToValidate.Email.Length > 0 && !Regex.IsMatch(contactToValidate.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
            //    _validationErrorCollection.Add("Email", "Invalid email address.");

           


        }
    }
}
